package com.project.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.project.daos.AdminMapper;
import com.project.entity.Users;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class AdminService {

    @Autowired
    private AdminMapper adminMapper;

    public PageInfo<Users> selAllUser(Integer roleId ,Integer currentPage,Integer pageSize){

        System.out.println(pageSize);
        PageHelper.startPage(currentPage,pageSize);
        List<Users> tenantUser = adminMapper.selAllTenant(roleId);
        for (int i = 0; i < tenantUser.size(); i++) {
            System.out.println(tenantUser.get(i).getUser_photo());
        }
        PageInfo<Users> usersPageInfo = new PageInfo<>(tenantUser);
        return usersPageInfo;
    }

    public PageInfo<Users> selConditionUser(Integer roleId ,String keyWord,Integer currentPage,Integer pageSize){
        PageHelper.startPage(currentPage,pageSize);
        List<Users> tenantUser = adminMapper.selConditionTenant(roleId,keyWord);
        PageInfo<Users> usersPageInfo = new PageInfo<>(tenantUser);
        return usersPageInfo;
    }

    public Integer delUser(Object[] ids){
        Integer delCount = adminMapper.delUser(ids);
        return delCount;
    }

    public Integer delOneUser(Integer id){
        Integer delCount = adminMapper.delOneUser(id);
        return delCount;
    }

    public Integer recoverUser(Object[] ids){
        Integer delCount = adminMapper.recoverUser(ids);
        return delCount;
    }

    public Integer recoverOneUser(Integer id){
        Integer delCount = adminMapper.recoverOneUser(id);
        return delCount;
    }

}
